export const API_URL: string = process.env.API_URL as string;
import axios from 'axios';
const service = axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  baseURL: API_URL,
  // 超时
  timeout: 100000,
});
service.interceptors.request.use(
  (config) => {
    config.headers.Accept = '*/*';

    config.headers['Content-Type'] = 'application/json;charset=utf-8';
    return config;
  },
  (err) => {
    console.warn('request-use-err', err);
  },
);
service.interceptors.response.use((response) => {
  const {
    data,
    headers: { status },
  } = response;
  const { errCode, error } = data;
  if (status === 401) {
    return response;
  }
  if (errCode || error) {
    if (errCode === '400001' || errCode === '400047' || error === 5000) {
      console.warn('unhandled error', errCode, error);
    }
    if (errCode === '500004') {
      console.warn('errCode', errCode);
    }
  }
  return response.data;
});
export default service;
